package com.xiaoa.gossip.cluster.action;

import com.xiaoa.gossip.cluster.command.PingCommand;
import com.xiaoa.gossip.cluster.command.PingNodeState;
import com.xiaoa.gossip.cluster.service.ClusterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 集群处理方法
 *
 * @author luokaichuang
 * @time 2020/5/7
 */
@RestController
@RequestMapping("cluster")
public class ClusterAction {

    @Autowired
    private ClusterService clusterService;

    @PostMapping("meet")
    public PingCommand meet(@RequestBody PingCommand pingCommand) {
        return clusterService.meet(pingCommand);
    }

    @PostMapping("ping")
    public PingCommand ping(@RequestBody PingCommand pingCommand) {
        return clusterService.ping(pingCommand);
    }

    @PostMapping("fail")
    public void fail(@RequestBody PingCommand pingCommand) {
        clusterService.doPongHandle(pingCommand);
    }

    @GetMapping("status")
    public List<PingNodeState> status() {
        return clusterService.noteList();
    }


}
